package com.ruoyi.wechat.controller;

import com.ruoyi.wechat.common.Constants;
import com.ruoyi.wechat.domain.dto.FileDTO;
import com.ruoyi.wechat.domain.vo.AjaxResult;
import com.ruoyi.wechat.service.ISysFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 文件上传
 * </p>
 *
 * @author YinHeng
 * @since 2024/2/18
 */
@RestController
@RequestMapping("/file")
public class FileUploadController {

    @Autowired
    private ISysFileService fileService;

    /**
     * 上传图片
     *
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file) throws Exception {
        String fileUrl = fileService.uploadFile(Constants.FileDirectory.DIRECTORY_COMMON.getValue(), file);
        FileDTO dto = new FileDTO();
        dto.setUrl(fileUrl);
        return AjaxResult.success(dto, "上传成功");
    }


}
